<template>
	<view class="device">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				设备回收
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}"></view>
		<view class="saoma">
			<image :src="baseUrl + '/wximage/saoma.png'" class="bj"></image>
			<view class="name">扫码回收设备</view>
		</view>
		<view class="footer" @click="scanCode">
			<view class="iconfont icon-iconfontscan"></view>
			<view class="submit">扫码回收</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		methods: {
			scanCode() {
				uni.scanCode({
					success: (res) => {
						// // 返回二维码路径,可以接收参数
						// var qrcodeNumber = res.result.split("=")[1];
						if(res.result){
							let url = res.result;
							
							let qrcodeurl = getApp().globalData.baseUrl;
							
							if(url.indexOf('/scan') > -1){
								var arrUrl = url.split('qrcodenumber=');
								// console.log(arrUrl[1]);
								var qrcode = arrUrl[1];
								var formData = {
									'qrcode': qrcode,
									'agentid': uni.getStorageSync('agent_id')
								}
								//请求接口回收设别
								this.request({
									url: '/wxdevice/reclaim',
									data: formData,
									method: "POST"
								}).then(res => {
									if (res.data.code == 200) {
										// var stores_id = res.data.data.id;//用户id
										uni.showToast({
											title: '回收成功',
											icon: 'none'
										});
											
									} else {
										uni.showToast({
											title: res.data.message,
											icon: 'none'
										});
									}
								})
								
							}
						}
						
					},
					fail: (res) => {
						console.log("未识别到二维码");
					}
					
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.device {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
		}

		.saoma {
			width: 94%;
			margin: 0 auto;
			margin-top: -190rpx;
			text-align: center;

			.bj {
				width: 400rpx;
				height: 406rpx;
			}

			.name {
				font-size: 36rpx;
				color: #333333;
				font-weight: 700;
				margin-top: 6rpx;
			}
		}

		.footer {
			width: 80%;
			margin: 0 auto 40rpx;
			margin-top: 360rpx;
			height: 72rpx;
			text-align: center;
			background: linear-gradient(90deg, #65bdfc, #398ef8);
			border-radius: 36rpx;
			border-top-left-radius: 0;
			border-bottom-left-radius: 42rpx;

			.iconfont {
				display: inline-block;
				margin-right: 14rpx;
				font-size: 34rpx;
				color: #ffffff;
			}

			.submit {
				display: inline-block;
				height: 72rpx;
				line-height: 72rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>